<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>发票资料信息</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div class="fieldset1 tabel_col tabel_col_s clearFix">
        <div class="sqPanel">
            <div class="sqPanel_head inL">
                <span>发票资料</span>
            </div>
            <div class="sqPanel_body">
                <div id="invoiceFileInfoGrid" class="sq-grid"></div>
            </div>
        </div>
    </div>
</div>

<div id="prjPrdDtl_file_div" style="display:none">
    <form id="prjPrdDtl_file_formSet">
        <div class="fieldset1 tabel_col noBorder clearFix">
            <div class="fieldBox col_100">
                <jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload.jsp" flush="true" >
                    <jsp:param name="fileNum" value="1"/>
                    <jsp:param name="filePath" value="capital/capPayInfo"/>
                </jsp:include>
            </div>
        </div>
        <input type="text" style="display: none;" id="id" value="${prjInsRfeRecordVO.id}">
        <input type="text" style="display: none;" id="cstId" name="cstId" value="${prjInsRfeRecordVO.cstId}">
        <input type="text" style="display: none;" id="insCode" name="insCode" value="${prjInsRfeRecordVO.insCode}">
        <input type="text" style="display: none;" id="prjId" value="${prjInsRfeRecordVO.prjId}">
    </form>
</div>
<script type="text/javascript">
    var fileNode = '${fileNode}';
    var detailFlag = '${detailFlag}';
    var invoiceFileInfoGrid = null;

    $(function () {
        invoiceFileInfoGrid.reload();
        $(document).on('click', 'a[name=showimg]', function(){
            event.preventDefault();
            var href = $(this).attr('href');
            reg = new RegExp('^.*\.(?:png|jpg|bmp|gif|jpeg|PNG|JPG|BMP|GIF|JPEG)$');
            if (reg.test(href)) {
                SQ.imgPreview(href);
            }else{
                window.open(href);
            }
        });
    });
    var invoiceFileListData = [];
    invoiceFileListData = ${invoiceFileList};
    invoiceFileInfoGrid = $("#invoiceFileInfoGrid").ligerGrid({
        data: {rows: invoiceFileListData, total: invoiceFileListData.length},
        columns: [
            {display: '资料名称', name: 'fileName', minWidth: 100, align: 'center', enabledSort: false},
            {display: '补件原因', name: 'fileMsg', minWidth: 100, align: 'center', enabledSort: false},
            {display: '上传文件名称', name: 'fileNm', minWidth: 100, align: 'center', enabledSort: false,
                render:function(rowdata,rowindex,value){
                    if(value){
                        //return '<a target="_blank" name="showimg" href="'+rowdata.filePath+'">'+rowdata.fileNm+'</a>';
                        var h;
                        h='<a href="javascript:uploadFileByUrl(';
                        h+="'"+rowdata.filePath+"'";
                        h+=",'"+rowdata.fileNm+"'";
                        h+=')">'+rowdata.fileNm+'</a>'
                        return h;
                    }
                }
            },
            {display: '上传时间', name: 'crtTm', minWidth: 100, align: 'center', enabledSort: false,render:renderDate},
            {display: '状态', name: 'audStsCdNm', width: 100, align: 'center', enabledSort: false},
            {display: '操作', name: '', minWidth: 100, align: 'center', enabledSort: false,
                render:function(rowdata,rowindex,value){
                    var h='';
                    if (detailFlag && fileNode == 2) {
                        /*if (fileNode == 1) {
                            if (rowdata.id && rowdata.audStsCd != 1) {
                                h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="delFile(event,' + rowdata.id + ');"><i class="sqBtnIco_7"></i>删除</a>';
                            }
                        } else if (fileNode == 2) {*/
                        if (rowdata.filePath) {
                            h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="modifyAudStsCd(event,' + rowdata.id + ',1);"><i class="sqBtnIco_15"></i>验证通过</a>';
                            h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="modifyAudStsCd(event,' + rowdata.id + ',2);"><i class="sqBtnIco_14"></i>验证不通过</a>';
                        }
                        return h;
                    }
                }
            },
            {display: '上传', name: '', width: 80,align: 'center', enabledSort: false,
                render:function(rowdata,rowindex,value){
                    var h='';
                    if(fileNode==1){
                        h+='<span class="sq-button sq-button-round fileupload-button">上传<input type="file" id="fileup_'+rowdata.filePkId+'_'+rowdata.cfgDtlCd+'" multiple name="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'"' +
                            ' class="fileupload-input" onchange="onChangefile_multi(event,\''+rowdata.filePkId+'\',\''+rowdata.cfgCd+'\',\''+rowdata.cfgDtlCd+'\',\''+rowdata.orgCd+'\',4)"></span>';                    }
                    return h;
                }
            }
        ],
        root: 'rows',
        hideLoadButton : true,
        width: '100%',
        height: '100%',
        isScroll: false,
        rownumbers:true,
        checkbox: false,
        allowUnSelectRow:true,
        alternatingRow: false,
        frozen: false,
        usePager: false
    });

    function onChangefile_multi(e,pkId,cfgCd,cfgDtlCd,orgCd,typ) {
        var wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
        var filePath="";
        var tabNm="";
        if(typ==1){
            filePath="customer";
            tabNm="CST_BSC_INFO";
        } else if (typ==2) {
            filePath="prjFileInfo";
            tabNm="PRJ_BSC_INFO";
        }else if (typ==3) {
            filePath="capital/capPayInfo";
            tabNm="PRJ_PRD_DTL";
        }else if (typ==4) {
            filePath="capital/capPayInfo";
            tabNm="PRJ_PRD_INVOICE";
        }else if (typ==5) {
            filePath="insPlc/insPlcInfo";
            tabNm="INS_PLC_BSC_INFO";
        }
        $.ajaxFileUpload({
            url: '<%=path%>/system/sysulfilesrec/upload.do',
            secureuri: false,
            fileElementId: e.target.id,  //这里不在是以前的id了，要写成数组的形式！
            dataType: 'json',
            data: {filePath: filePath},
            success: function (msg) {
                if (msg.success == 1) {
                    $.ajax({
                        type: 'post',
                        dataType: 'json',
                        data: {'fileParams':JSON.stringify(msg.data),
                            'pkId':pkId,
                            'cfgCd':cfgCd,
                            'cfgDtlCd':cfgDtlCd,
                            'orgCd':orgCd,
                            'tabNm':tabNm
                        },
                        url: '<%=path%>/insitution/prjInsRfeRecord/uploadFileInfo.do',
                        success: function (msg) {
                            if (msg.success == 1) {
                                window.location.reload(true);
                                top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                                wait_dialog.close();
                            }else{
                                $.ligerDialog.SQalert({content: "资料上传超时", SQ_type: "error"});
                            }
                            $.ligerDialog.hide();
                        }
                    });
                } else {
                    wait_dialog.close();
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

    //删除文件
    function delFile(event,_fileId){
        top.$.ligerDialog.confirm("确认删除吗?", function (flag) {
            if(!flag){
                return;
            }else{
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {'fileId':_fileId},
                    url: '<%=path%>/project/prjFileInfo/removeFile.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            window.location.reload(true);
                        }else{
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            }
        });
    }

    //修改资料的验证状态
    function modifyAudStsCd(event,_fileId,_audStsCd){
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {'fileId':_fileId,'audStsCd':_audStsCd},
            url: '<%=path%>/project/prjFileInfo/modifyFileAudStsCd.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                if (msg.success == 1) {
                    window.location.reload(true);
                    top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                    wait_dialog.close();
                }else{
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    function uploadFileByUrl(_url,_name){
        if(SQ.regs.img.test(_name)){
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        }else if(SQ.regs.img.test(_url)){
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        }else{
            window.open(_url);
        }
    }

</script>
</body>
</html>
